package com.solotiger.learn.andengine;

import android.content.Context;
import android.view.Gravity;
import android.view.View;
import android.view.ViewGroup;
import android.widget.AbsListView;
import android.widget.BaseExpandableListAdapter;
import android.widget.TextView;

/**
 * 类描述:自定义ExpandableListAdapter
 * 
 * @Author:solotiger
 * @Date:2012-10-14
 */
public class MyExpandableListAdapter extends BaseExpandableListAdapter {

	private Context mContext;

	private String[] arrs;
	private String[][] children;

	public MyExpandableListAdapter(Context ctx) {
		mContext = ctx;
		// arrs = ctx.getResources().getStringArray(R.array.arrs);
		// children = new String[][] {
		// ctx.getResources().getStringArray(R.array.simpleEx),
		// ctx.getResources().getStringArray(R.array.textEx) };
	}

	@Override
	public String getChild(int groupPosition, int childPosition) {
		return children[groupPosition][childPosition];
	}

	@Override
	public long getChildId(int groupPosition, int childPosition) {
		return childPosition;
	}

	public TextView getGenericView() {
		AbsListView.LayoutParams lp = new AbsListView.LayoutParams(ViewGroup.LayoutParams.MATCH_PARENT, 64);
		TextView textView = new TextView(mContext);
		textView.setLayoutParams(lp);
		textView.setGravity(Gravity.CENTER_VERTICAL | Gravity.LEFT);
		textView.setPadding(36, 0, 0, 0);
		return textView;
	}

	@Override
	public View getChildView(int groupPosition, int childPosition, boolean isLastChild, View convertView, ViewGroup parent) {
		TextView textView = getGenericView();
		textView.setText(getChild(groupPosition, childPosition).toString());
		return textView;
	}

	@Override
	public int getChildrenCount(int groupPosition) {
		return children[groupPosition].length;
	}

	@Override
	public String getGroup(int groupPosition) {
		return arrs[groupPosition];
	}

	@Override
	public int getGroupCount() {
		return arrs.length;
	}

	@Override
	public long getGroupId(int groupPosition) {
		return groupPosition;
	}

	@Override
	public View getGroupView(int groupPosition, boolean isExpanded, View convertView, ViewGroup arg3) {
		TextView textView = getGenericView();
		textView.setText(getGroup(groupPosition).toString());
		return textView;
	}

	@Override
	public boolean hasStableIds() {
		return true;
	}

	@Override
	public boolean isChildSelectable(int arg0, int arg1) {
		return true;
	}

}
